package com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.iterator.impl;

import com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.entity.MenuItem;
import com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.iterator.Iterator;

import java.util.ArrayList;

/**
 * 煎饼屋迭代器
 * @author 、
 */
public class PancakeHouseMenuIterator implements Iterator {

    /**
     * 可变长数组
     */
    private ArrayList<MenuItem> items;

    /**
     * 迭代下标
     */
    private int position;

    public PancakeHouseMenuIterator(ArrayList<MenuItem> items) {
        this.items = items;
    }

    @Override
    public boolean hasNext() {
        return position < items.size() && items.get(position) != null;
    }

    @Override
    public Object next() {
        MenuItem menuItem = items.get(position);
        position = position + 1;
        return menuItem;
    }

}
